package com.ssy.lingxi.product.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.request.warehouse.*;
import com.ssy.lingxi.product.api.model.response.warehouse.InvoicesDetailsResponse;
import com.ssy.lingxi.product.entity.warehouse.InvoicesImportBatchNo;
import com.ssy.lingxi.product.api.model.response.warehouse.InvoicesListResponse;
import com.ssy.lingxi.product.service.InvoicesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu APP-进销存-单据管理
 * @author wrc
 * @date 2020/7/20
 */
@RestController
@RequestMapping("/product/mobile")
public class MobileInvoicesController extends BaseController {
    @Resource
    InvoicesService invoicesService;

    /**
     * 单据管理列表查询
     */
    @GetMapping("/invoices/list")
    public Wrapper<PageData<InvoicesListResponse>> invoicesList(InvoicesListRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return invoicesService.invoicesList(request,sysUser);
    }

    /**
     * 添加/修改单据
     */
    @PostMapping("/invoices/addOrUpdate")
    public Wrapper<Void> invoicesAddOrUpdate(@Valid @RequestBody InvoicesAddOrUpdateRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return invoicesService.invoicesAddOrUpdate(request,sysUser);
    }

//    @ApiOperation(value = "单据导入")
//    @PostMapping("/invoices/import/excel")
//    public Wrapper importExcel(@RequestParam(value = "file")MultipartFile file) {
//        return invoicesService.importExcel(file);
//    }
//
//    @ApiOperation(value = "单据导入检查")
//    @PostMapping("/invoices/import/excel/check")
//    public Wrapper importExcelCheck(@RequestParam(value = "file")MultipartFile file) {
//        return invoicesService.importExcelCheck(file);
//    }

    @ApiOperation(value = "单据单个删除/批量删除")
    @PostMapping("/invoices/batch/delete")
    public Wrapper invoicesDelete(@RequestBody InvoicesDeleteRequest request) {
        return invoicesService.invoicesDelete(request);
    }

    /**
     * 单据单个审核/批量审核
     * 单据单个反审/批量反审
     * @param request
     * @return
     */
    @PostMapping("/invoices/batch/review")
    public Wrapper<Void> invoicesReview(@Valid @RequestBody InvoicesReviewRequest request) {
        return invoicesService.invoicesReview(request);
    }

    @ApiOperation(value = "查询导入批次号列表")
    @GetMapping("/invoices/import/batch/list")
    public Wrapper<List<InvoicesImportBatchNo>> invoicesImportBatchList(InvoicesImportBatchListRequest request) {
        return invoicesService.invoicesImportBatchList(request);
    }

    @ApiOperation(value = "删除批次")
    @PostMapping("/invoices/import/batch/delete")
    public Wrapper invoicesImportBatchDelete(@RequestBody InvoicesImportBatchDeleteRequest request) {
        return invoicesService.invoicesImportBatchDelete(request);
    }

    @ApiOperation(value = "添加单据内部接口")
    @PostMapping("/invoices/feign/add")
    public Wrapper<Void> invoicesAddFeign(@Valid @RequestBody InvoicesAddFeignRequest request) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        InvoicesAddOrUpdateRequest invoicesAddRequest = new InvoicesAddOrUpdateRequest();
        BeanUtils.copyProperties(request, invoicesAddRequest);
        return invoicesService.invoicesAddOrUpdate(invoicesAddRequest, sysUser);
    }

    @ApiOperation(value = "查看单据详情")
    @GetMapping("/invoices/details")
    public Wrapper<InvoicesDetailsResponse> invoicesDetails(Long id) {
        return invoicesService.invoicesDetails(id);
    }

    /**
     * 根据单号查看单据详情
     * @author wrc
     * @date 2021/1/4
     */
    @GetMapping("/invoices/details/byNo")
    public Wrapper<InvoicesDetailsResponse> invoicesDetailsByNo(InvoicesDetailsByNoRequest request) {
        return invoicesService.invoicesDetailsByNo(request);
    }
}
